﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmallERP.MODEL.FoundationModel;
using SmallERP.DAL;
using System.Data;
using Smallerp.Contracts;

namespace SmallERP.Bll.PrintManage
{
    public class PrinterBLL
    {
        IOperateDB _OperateDb;
        public PrinterBLL(IOperateDB inDB)
        {
            _OperateDb = inDB;
        }
        public Printer_info GetPrinter(string name)
        {
            Printer_info printerInfo = new Printer_info();
            string QueryPrinter = "select * from printer  where PName='" + name+"'";
            DataTable Qtable = _OperateDb.QueryDataTable(QueryPrinter);
            if (Qtable.Rows.Count > 0)
            {

                printerInfo.HotDirPath = Qtable.Rows[0]["hotDirPath"].ToString();
                printerInfo.IsTransverse = Convert.ToBoolean(Qtable.Rows[0]["IsTransverse"]);
                printerInfo.MonitorDirPath = Qtable.Rows[0]["MonitorDirPath"].ToString();
                printerInfo.PDes = Qtable.Rows[0]["PDes"].ToString(); ;
                printerInfo.PDPI = Convert.ToInt32(Qtable.Rows[0]["PDPI"]); ;
                printerInfo.PLength = Convert.ToDouble(Qtable.Rows[0]["PLength"]);
                printerInfo.PName = Qtable.Rows[0]["PName"].ToString();
                printerInfo.PrinterID = Convert.ToInt32(Qtable.Rows[0]["PrinterID"]);
                printerInfo.PWidth = Convert.ToInt32(Qtable.Rows[0]["PWidth"]);
                printerInfo.PrintStatus = Convert.ToInt32(Qtable.Rows[0]["PrintStatus"]);
                printerInfo.PBstatus = Convert.ToInt32(Qtable.Rows[0]["PBstatus"]);
                printerInfo.HotFolderUserName = Convert.ToString(Qtable.Rows[0]["HotFolderUserName"]);
                printerInfo.HotFolderPwd = Convert.ToString(Qtable.Rows[0]["HotFolderPwd"]);

            }
            else
            {
                printerInfo = null;
            }

            return printerInfo;
        }

        public List<Printer_info> GetPrinterList()
        {
            List<Printer_info> list = new List<Printer_info>();
            string QueryPrinter = "select * from printer ";
            DataTable Qtable = _OperateDb.QueryDataTable(QueryPrinter);
            for (int i = 0; i < Qtable.Rows.Count; i++)
            {
                Printer_info printerInfo = new Printer_info();
                printerInfo.HotDirPath = Qtable.Rows[i]["hotDirPath"].ToString();
                printerInfo.IsTransverse = Convert.ToBoolean(Qtable.Rows[i]["IsTransverse"]);
                printerInfo.MonitorDirPath = Qtable.Rows[i]["MonitorDirPath"].ToString();
                printerInfo.PDes = Qtable.Rows[i]["PDes"].ToString(); ;
                printerInfo.PDPI = Convert.ToInt32(Qtable.Rows[i]["PDPI"]); ;
                printerInfo.PLength = Convert.ToDouble(Qtable.Rows[i]["PLength"]);
                printerInfo.PName = Qtable.Rows[i]["PName"].ToString();
                printerInfo.PrinterID = Convert.ToInt32(Qtable.Rows[i]["PrinterID"]);
                printerInfo.PWidth = Convert.ToInt32(Qtable.Rows[i]["PWidth"]);
                printerInfo.PrintStatus = Convert.ToInt32(Qtable.Rows[i]["PrintStatus"]);
                printerInfo.PBstatus = Convert.ToInt32(Qtable.Rows[i]["PBstatus"]);
                printerInfo.HotFolderUserName = Convert.ToString(Qtable.Rows[0]["HotFolderUserName"]);
                printerInfo.HotFolderPwd = Convert.ToString(Qtable.Rows[0]["HotFolderPwd"]);
                list.Add(printerInfo);
            }
            return list;
        }
    }
}
